package com.jiufen.Controller;


import com.jiufen.Pojo.Result;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping("/cookie")
public class CookieTestController {
    /**
     * 设置cookie
     */
    @GetMapping("/Cookie1")
    public Result setCookie1(HttpServletResponse response) {
        response.addCookie(new Cookie("login_username", "jiufen"));
        return Result.success();
    }


    /**
     * 获取cookie
     */
    @GetMapping("/Cookie2")
    public Result getCookie(HttpServletRequest request) {
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies) {
//            if (cookie.getName().equals("login_username")) {
//                log.debug("cookie_loginUsername:{}", cookie.getValue());
//            }
            log.debug("cookie:{}", cookie.getName() + ":" + cookie.getValue());
        }
        return Result.success();
    }
}
